var A=(function($){
	var Anny = function(){
		this.$ = $;
		this.options = {
			version : '0.0.1',
			showlogtype:1 		//0关闭  1 console.log 2 alert 

		};

	};
	

	Anny.prototype.launch = function(opts){

	};

	Anny.prototype.register = function(key, obj){
		this[key] = obj;
	};

	return new Anny();
})(window.Zepto||jQuery);


//ajax封装
(function($){
	//用法继承jQuery的$.ajax
	var ajax = function(opts){
		
		var success = opts.success;
		var error = opts.error;
		
		var random = '__ajax_random__='+Math.random();
    	opts.url += (opts.url.split(/\?|&/i).length==1?'?':'&')+random;

		var _success = function(data){
			success&&success(data);
		};
		var _error = function(data){
			error&&error();
		};

		opts.success = _success;
		opts.error = _error;
		
		$.ajax(opts);
	};
	A.register('ajax', ajax);
})(A.$);

//弹出组
(function($){
    var Popup = function(opts){

	};    
	Popup.prototype.open = function(callback){

	};

	Popup.prototype.close = function(callback){
	    //return this;
	};
	A.register('Popup' , Popup);

	var _ex = {};
	//alert
	_ex.alert=function(str){
		alert(str);
	};
	_ex.confirm=function(str,fun){
		var cf=confirm(str);
		if(cf){
			if(typeof(fun)=='function'){
				fun();
			}
		}
	};
	//
	_ex.showMask=function(){
		console.log('showMask');
	};
	_ex.hideMask=function(){
		console.log('hideMask');
	};

	for(h in _ex){
		A.register(h, _ex[h]);
	}	
})(A.$);

//列表
(function($){
    var List = function(el,opts){

	}; 
	List.prototype.Tab = function(opt){

	};
	List.prototype.Search = function(opt){

	};			
	List.prototype.Select = function(opt){

	};
	List.prototype.Setparm = function(opt){

	};
	List.prototype.Del = function(opt){

	};
	List.prototype.Add = function(opt){

	};
	List.prototype.Modify = function(opt){

	};
	List.prototype.Lookup = function(opt){

	};
	List.prototype.Refresh = function(opt){

	};	
	List.prototype.CreateList = function(opt){

	};
	List.prototype.Pagination = function(opt){

	};		
	A.register('List', List);
})(A.$);
//表格
(function($){
    var Form = function(el,opts){
    	var obj=$(el);
    	var that=this;
    	var o={
    		url:'',
    		submitbtn:null,
    		callback:null,
    		beforefun:function(){
    			return true;
    		}
    	};
    	o=$.extend(o, opts.submit);
    	
    	that.init=function(el,op){
    		if(opts.init==false){
    			return;
    		}
    		var url=$(el).data('source');
    		var data=null;
    		var reslut;
    		if(typeof(opts.init.getData)=='function'){
    			data=opts.init.getData();
    		}
    		
    		if(url){
    			reslut=AjaxPost(url,data,null,false);
    			printf(el,reslut);
    		}
    		if(typeof(op)=="function"){//
    			op(el,reslut);
    		}   

    		if(o.submitbtn==null){
    			o.submitbtn=$(el).find('[data-submit]');
    			o.url=$(o.submitbtn).data('submit');
    		}

    		$(o.submitbtn).off('click').on('click',function(){
    			that.submit(el);
    		});

    	};
    	that.submit=function(el){
    		if(o.url==null||o.url==''){
    			that.checkform(el);

    		}else{
    			if(that.checkform(el)){
    				AjaxPost(o.url,that.getdata(),o.callback);
    			}
    		}
    	};
    	that.checkform=function(el){
    		if(!o.beforefun()){
    			return false;
    		}
    		return that.checkElement(el);
    	};
    	that.checkElement=function(el){
    		return true;
    	}
    	that.getdata=function(){
    		return getFormData(el);
    	}; 
    	that.init(el,opts.init);
    	return that;
	}; 	
	A.register('Form', Form);
})(A.$);
//页面初始化
(function($){
    var Page = function(el){
    	var obj= $(el);
    	var that=this;
 		var page=obj.data('page');
 		var opts=obj.data('init');
 		that.Init=function(el,opt){
 			var _F=$(el).find('[data-form]');
 			var _L=$(el).find('[data-list]');
 			var opts;
 			if(typeof(opt)=="string"){
 				opts=menu[opt];
 			}
 			if(typeof(opts.form)=='object'){
	 			$.each(_F, function(index, _form) {
	 				A.Form(_form,opts.form[index]);
	 			});
 			}
 			if(typeof(opts.list)=='object'){
	 			$.each(_L, function(index, _form) {
	 				A.List(_form,opts.list[index]);
	 			});
 			}
 			if(typeof(opts.fun)=='function'){
 				opts.fun();
 			}

 		}
 		if(page==null||page==''){
 			that.Init(obj,opts);	
 			return;
 		};
 		obj.load(htmlpath+page,function(){
 			that.Init(el,opts);	
 		});
 		return that;

	}; 
	A.register('Page', Page);
})(A.$);
//调试输出
(function($){
    var ShowLog = function(opts){
    	if(A.options.showlogtype==0){//调试功能关闭
    		return;
    	}

    	if(typeof(opts)=='function'){//调试功能使用一个自定义函数
    		opts();
    	}else{
    		var str='';
    		var numargs = arguments.length;
    		for(var i=0;i<numargs;i++){//将多个参数合并
    			str += arguments[i];
    		}
    		if(A.options.showlogtype==1){
    			console.log(str);
    		}else if(A.options.showlogtype==2){
    			alert(str);
    		}
    	}
	}; 	
	A.register('ShowLog', ShowLog);
})(A.$);
